var itemId = 0;

function getVLC(name) {
	if (window.document[name]) {
		return window.document[name];
	}
	if (navigator.appName.indexOf("Microsoft Internet") == -1) {
		if (document.embeds && document.embeds[name])
			return document.embeds[name];
	}
	else {
		return document.getElementById(name);
	}
}

function doGo(mrl) {
	console.log('当前测试地址：'+mrl)
	var vlc = getVLC("vlc");
	if (vlc && vlc.playlist) {
		itemId = vlc.playlist.add(mrl);
		vlc.playlist.playItem(itemId);
		vlc.audio.mute = true;
	} else {
		return;
	}
}

function doPlay() {
	vlc.playlist.playItem(itemId);
}

function doStop() {
	getVLC("vlc").playlist.stop();
}

function _checkPlay(mrl) {
	var vlc = getVLC("vlc");
	if (vlc.playlist && vlc.playlist.isPlaying == false) {
		vlc.playlist.clear();
		itemId = vlc.playlist.add(mrl);
		vlc.playlist.playItem(itemId);
		setTimeout(function () {
			_checkPlay();
		}, 200);
	}
}

// window.onload = function() {
// 	// TODO 需要获取地址传过来的摄像头id，根据id获取rtsp信息
// 	var ip = getParam('rtsp');
// 	// console.log(ip);
// 	// var vlc_url = "rtsp://guest:uin123456@192.168.2.41:554/h265/ch1/main/av_stream&options=rtptransport=tcp";
// 	var vlc_url = ip;
// 	doGo(vlc_url);
// 
// 	// setTimeout(function () {
// 	// 	_checkPlay(vlc_url);
// 	// }, 200);
// }
function getParam(name) {
	var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
	var r = window.location.search.substr(1).match(reg);
	if (r != null) {
		return unescape(r[2]);
	}
	return null;
}